﻿#region Copyright(C) 2010-2010 NCS Pte. Ltd. All rights reserved.
// ==================================================================================================
// Copyright(C) 2010 NCS Pte. Ltd. All rights reserved.
//
// SYSTEM NAME	    : iConnect .Net Application Framework
// COMPONENT ID	    : NCS.IConnect.Core.Wcf
// COMPONENT DESC   : Core components for WCF.	
//
// CREATED DATE/BY  : 18 Aug 2010 / Gao Ye
//
// REVISION HISTORY :	
// DATE/BY			SR#/CS/PM#/OTHERS		DESCRIPTION OF CHANGE
// ==================================================================================================
#endregion

using System.Text;
using System.ServiceModel.Configuration;
using System.Configuration;
using System;

namespace NCS.IConnect.Core.IoC.Wcf
{
    /// <summary>
    /// The <see cref="BehaviorExtensionElement"/> for <see cref="ServiceLocationBehaviorAttribute"/>.
    /// </summary>
    public class ServiceLocationBehaviorElement : BehaviorExtensionElement
    {
        private const string serviceLocatorNameProperty = "serviceLocator";

        /// <summary>
        /// Gets or sets the name of the service locator.
        /// </summary>
        /// <value>The name of the service locator.</value>
        [ConfigurationProperty(serviceLocatorNameProperty, IsRequired = false, DefaultValue = "")]
        public string ServiceLocatorName
        {
            get
            {
                return (string)this[serviceLocatorNameProperty];
            }
            set
            {
                this[serviceLocatorNameProperty] = value;
            }
        }

        /// <summary>
        /// Gets the type of behavior.
        /// </summary>
        /// <value></value>
        /// <returns>A <see cref="T:System.Type"/>.</returns>
        public override Type BehaviorType
        {
            get { return typeof(ServiceLocationBehaviorAttribute); }
        }

        /// <summary>
        /// Creates a behavior extension based on the current configuration settings.
        /// </summary>
        /// <returns>The behavior extension.</returns>
        protected override object CreateBehavior()
        {
            if (!string.IsNullOrEmpty(this.ServiceLocatorName))
            {
                return new ServiceLocationBehaviorAttribute(this.ServiceLocatorName);
            }
            else
            {
                return new ServiceLocationBehaviorAttribute();
            }
        }
    }
}
